//
//  UIBarButtonItemExtension.swift
//  WEIBO_SWIFT
//
//  Created by 岳挺 on 15/6/30.
//  Copyright © 2015年 yueting. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    convenience init(imageName : String , highlightImageName : String?){
        let btn = UIButton()
        btn.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        let str = highlightImageName ?? imageName + "_highlighted"
        btn.setImage(UIImage(named: str), forState: UIControlState.Highlighted)
        btn.sizeToFit()
        self.init(customView: btn)
    }
    
    convenience init(imageName : String , highlightImageName : String? , target : AnyObject , actionName : String?){
        let btn = UIButton()
        btn.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        let str = highlightImageName ?? imageName + "_highlighted"
        btn.setImage(UIImage(named: str), forState: UIControlState.Highlighted)
        btn.sizeToFit()
        if actionName != nil{
            btn.addTarget(target, action: Selector(actionName!), forControlEvents: UIControlEvents.TouchUpInside)
        }
        self.init(customView: btn)
    }
}